import Router from 'koa-router'
import config from '../config'
import wxMidWare from '../wechat-lib/wxMidWare'
import reply from '../wechat/reply'
import { wechat } from '../controller'
// import { resolve } from 'path'
const router = new Router()
export default app => {
  router.all('/wechat', wxMidWare(config.wechat, reply))
  router.get('/upload', async (ctx, next) => {
    // const data = await client.handler('uploadMeterial', 'video', resolve(__dirname, '../../meterial/temp1.mp4'), {
    //   description: {
    //     title: 'Test',
    //     introduction: 'test one !!!'
    //   }
    // })
    // const data = await client.handler('uploadMeterial', 'image', resolve(__dirname, '../../meterial/pngtest.png'))
    // const data = await client.handler('uploadMeterial', 'image', resolve(__dirname, '../../meterial/pngtest.png'), true)
    // const news = {
    //   'articles': [
    //     {
    //       'title': 'news test1',
    //       'thumb_media_id': 'DlPVGUXQ0_v2ZoLv_4XhZhEqzTwYnZ2NozIkebcUdrE',
    //       'author': 'valon',
    //       'digest': 'test digest1',
    //       'show_cover_pic': 1,
    //       'content': 'has pic',
    //       'content_source_url': 'https://juejin.im'
    //     },
    //     {
    //       'title': 'news test2',
    //       'thumb_media_id': 'DlPVGUXQ0_v2ZoLv_4XhZhEqzTwYnZ2NozIkebcUdrE',
    //       'author': 'valon',
    //       'digest': 'test digest2',
    //       'show_cover_pic': 0,
    //       'content': 'has not pic',
    //       'content_source_url': 'http://www.baidu.com'
    //     }
    //   ]
    // }
    // const data = await client.handler('uploadMeterial', 'news', news, true)
  })
  router.get('/wx-signature', wechat.signature)
  router.get('/wx-redirect', wechat.redirect)
  router.get('/wx-authorize', wechat.authorize)
  router.get('/ctxreq', async function (ctx, next) {
    ctx.request['bingo'] = 'req area data test'
    ctx.redirect('/about')
  })
  app.use(router.routes())
     .use(router.allowedMethods())
}
